﻿import QtQuick 2.4
//import QtQuick 2.13
import QtQuick.Layouts 1.13
import QtQuick.Controls 2.5
// 导入自定义包
import com.mycompany.customType 1.0

Item {
    //id: root
    width: 300
    height: 400

    property alias stackLayoutSearch: stackLayoutSearch
    //property alias pageLowEnergy: pageLowEnergy
    //property alias pageDevice: pageDevice
    //property alias mouseAreaList: mouseAreaList
    property alias searchBtn: searchBtn
    property alias listViewDevice: listViewDevice
    property alias listViewLowEnergyInfo: listViewLowEnergyInfo
    property alias btnReturnSearch: btnReturnSearch
    property alias textLowEnergyDeviceName: textLowEnergyDeviceName
    property alias textLowEnergyDeviceAddr: textLowEnergyDeviceAddr
    property alias editDeviceFilter: editDeviceFilter

    StackLayout {
        id: stackLayoutSearch
        currentIndex: 0
        anchors.fill: parent

        Page {
            //id: pageDevice
            header: Column {
                width: parent.width

                /*Label {
                    text: "蓝牙设备"
                    anchors.horizontalCenter: parent.horizontalCenter
                    background: Rectangle {
                        anchors.fill: parent
                        color: "white"
                    }
                }*/
                TextField {
                    id: editDeviceFilter
                    text: qsTr("")
                    placeholderText: "模糊过滤(蓝牙地址|蓝牙名称)"
                    width: parent.width
                }
            }
            ListView {
                id: listViewDevice
                //objectName: "listViewDevice"
                anchors.fill: parent
                focus: true
                cacheBuffer: 1000000000 // 这个值不能太小，否则itemAtIndex会获取值为空，遍历的时候就会失败
                //width: parent.width
                //height: parent.height - searchBtn.height
                //header:
                headerPositioning: ListView.OverlayHeader
                //MouseArea {
                //   id: mouseAreaList
                //    anchors.fill: parent
                //    acceptedButtons: Qt.LeftButton | Qt.RightButton
                //    propagateComposedEvents: true
                //}
                delegate: delegateDeviceList
                //model: bluetoothDeviceModel
                //model: BluetoothDeviceModelSingleton
                model: BluetoothDeviceModel {
                    id: bluetoothDeviceModel
                    objectName: "bluetoothDeviceModel"
                }
                highlight: highlightDevice
                highlightFollowsCurrentItem: false
            }
            footer: ToolBar {
                contentHeight: 20 //searchBtn.height
                Button {
                    id: searchBtn
                    //height: 20
                    width: parent.width
                    text: qsTr("搜索")
                }
            }
        }
        Page {
            //id: pageLowEnergy
            //anchors.fill: parent
            header: ToolBar {
                contentHeight: btnReturnSearch.implicitHeight
                ToolButton {
                    id: btnReturnSearch
                    text: ""
                    icon.source: "/image/return.png"
                    display: AbstractButton.IconOnly
                    //font.pixelSize: Qt.application.font.pixelSize * 1.6
                }
                Column {
                    anchors.centerIn: parent
                    Text {
                        id: textLowEnergyDeviceName
                        width: Math.max(textLowEnergyDeviceName.implicitWidth,
                                        textLowEnergyDeviceAddr.implicitWidth)
                        text: "蓝牙名称"
                        horizontalAlignment: Text.AlignHCenter
                        font.bold: true
                        font.pixelSize: 15
                        font.family: customFont.name
                    }
                    Text {
                        id: textLowEnergyDeviceAddr
                        width: Math.max(textLowEnergyDeviceName.implicitWidth,
                                        textLowEnergyDeviceAddr.implicitWidth)
                        text: "蓝牙地址"
                        horizontalAlignment: Text.AlignHCenter
                        anchors.topMargin: 2
                        font.bold: true
                        font.pixelSize: 11
                        font.family: customFont.name
                        color: "gray"
                    }
                }
            }
            ListView {
                id: listViewLowEnergyInfo
                //objectName: "listViewLowEnergy"
                anchors.fill: parent
                focus: true
                cacheBuffer: 1000000000 // 这个值不能太小，否则itemAtIndex会获取值为空，遍历的时候就会失败


                /*header: Label {
                        text: "低功耗蓝牙设备"
                        anchors.horizontalCenter: parent.horizontalCenter
                    }
                    headerPositioning: ListView.OverlayHeader
                    */
                //MouseArea {
                //   id: mouseAreaList
                //    anchors.fill: parent
                //    acceptedButtons: Qt.LeftButton | Qt.RightButton
                //    propagateComposedEvents: true
                //}
                delegate: delegateLowEnergyInfoList
                //model: bluetoothDeviceModel
                //model: BluetoothDeviceModelSingleton
                model: LowEnergyInfoModel {
                    id: lowEnergyInfoModel
                    objectName: "lowEnergyInfoModel"
                }
                highlight: highlightDevice
                highlightFollowsCurrentItem: false
            }
        }
    }
}
